package uk.gov.swmprobation.cpvisibility;

import java.util.List;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

public class NetworkChange extends BroadcastReceiver {
	
	@Override
	public void onReceive(Context context, Intent intent) {
		if(Helper.checkWifi(context)){
	        DatabaseHandler.getInstance(context);
			List<Integer> waitingIds = DatabaseHandler.getWaitingIds();
			if(waitingIds.size()==0) return;
			for(int i=0;i<waitingIds.size();i++){
				Intent serviceIntent = new Intent(context, SendWaiting.class);
				serviceIntent.putExtra("localId", waitingIds.get(i));
				context.startService(serviceIntent);
			}
		}
		if ("android.intent.action.BOOT_COMPLETED".equals(intent.getAction())){
			Intent MQTTIntent = new Intent(context,MQTTConnection.class);
			context.startService(MQTTIntent);
		}
	}
	
}
